package com.hnkywl.sts.entity.cggl;

import com.hnkywl.sts.entity.BaseEntity;
import com.hnkywl.sts.entity.base.Fj;
import com.hnkywl.sts.entity.htgl.Cght;
import com.hnkywl.sts.entity.organ.*;
import com.hnkywl.sts.entity.sys.Yg;
import com.hnkywl.sts.entity.xsgl.Kh;
import com.hnkywl.sts.entity.xsgl.Xsd;
import org.hibernate.annotations.*;

import javax.persistence.*;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: ZHUCHG
 * Date: 13-4-15
 * Time: 下午3:00
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "T_BIZ_CGD")
@Where(clause = "deleted!='1'")
public class Cgd extends BaseEntity {
    @Id
    @SequenceGenerator(name = "seqCgd", allocationSize = 1, sequenceName = "SEQ_BIZ_CGD")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seqCgd")
    private Long id;

    /**
     * 采购单号
     */
    private String cgdh;

    /**
     * 采购类型   cgrk 采购入库  zddh  直达到货  tpcght  统配采购 bght  保供采购
     */
    private String cglx;

    //供应商
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "GYS_ID")
    private Gsjg gys;

    //发货公司
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "FHGS_ID")
    private Gsjg fhgs;

    //采购合同
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "CGHT_ID")
    @NotFound(action = NotFoundAction.IGNORE)
    private Cght cght;
    //承运号
    private String cyh;

    //到站
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "DZCK_ID")
    private Ck dzck;
    //发货日期
    private Date fhrq;
    //计划到货日期
    private Date jhdhrq;
    //运输单位
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "YSDW_ID")
    private Wls ysdw;
    //运输工具识别码
    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(
            name = "T_CGD_YSGJ",
            joinColumns = @JoinColumn(name = "CGD_ID"),
            inverseJoinColumns = @JoinColumn(name = "YSGJ_ID")
    )
    private List<Ysgj> ysgjList;
    //联系人电话
    private String lxrdh;
    //采购时间（年月旬）
    private Date cgsj;
    //税率
    private String sl;
    //备注
    private String bz;
    //申报公司
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "SBGS_ID")
    private Gsjg sbgs;
    //申报部门
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "SBBM_ID")
    private Gsjg sbbm;
    //申报人
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "SBR_ID")
    private Yg sbr;

    //采购公司
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "CGGS_ID")
    private Gsjg cggs;
    //采购部门
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "CGBM_ID")
    private Gsjg cgbm;
    //采购人
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "CGR_ID")
    private Yg cgr;
    //采购单明细
    @OneToMany(fetch = FetchType.LAZY, targetEntity = Cgdmx.class)
    @Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
    @JoinColumn(name = "CGD_ID")
    private List<Cgdmx> cgdmxList;
    //关联费用
    @OneToMany(fetch = FetchType.LAZY)
    @Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
    @JoinColumn(name = "CGD_ID")
    @Where(clause = "deleted!='1'")
    private List<Glfy> cgfyList;
    //是否调整单
    private boolean sftzd = false;
    //关联调整单
    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "GLTZD_ID")
    @NotFound(action = NotFoundAction.IGNORE)
    private Cgd gltzd;
    //结算单
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "CGJS_ID")
    @NotFound(action = NotFoundAction.IGNORE)
    private Jsd cgjsd;
    //销售单
    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "XSD_ID")
    @NotFound(action = NotFoundAction.IGNORE)
    private Xsd xsd;

    //补充采购单
    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "BCCGD_ID")
    @NotFound(action = NotFoundAction.IGNORE)
    private Cgd bccgd;

    /**
     * 状态  yrk
     */
    private String zt;

    /**
     * 调整申请状态  wsq，ysq，ysp
     */
    private String tzsqzt;

    /**
     * 是否验收
     */
    private Boolean sfys = false;

    /**
     * 验收人
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "YSR_ID")
    private Yg ysr;

    /**
     * 验收时间
     */
    private Date ysrq;

    /**
     * 是否内部
     */
    private Boolean sfnb = false;

    /**
     * 已审核
     */
    private Boolean ysh = false;

    /**
     * 已入库
     */
    private Boolean yrk = false;

    /**
     * 已结算
     */
    private Boolean yjs = false;


    /**
     * 代收运费金额
     */
    private Double dsyfje;

    /**
     * 入库时间
     */
    private Date rksj;

    //入库人
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "RKR_ID")
    private Yg rkr;


    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "YCGD_ID")
    @NotFound(action = NotFoundAction.IGNORE)
    private Cgd ycgd;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "LJ_ID")
    @NotFound(action = NotFoundAction.IGNORE)
    private Lj lj;

    /**
     * 入库结束
     */
    private Boolean endFlag = false;

    @Formula("(select sum(t.SBSL) from T_BIZ_CGDMX t where t.CGD_ID=ID and DELETED!=1)")
    private Double cgsl;

    @Formula("(select sum(t.HSJ*t.SBSL) from T_BIZ_CGDMX t where t.CGD_ID=ID and DELETED!=1)")
    private Double cgje;

    @Formula("(select sum(t.BHSJ*t.SBSL) from T_BIZ_CGDMX t where t.CGD_ID=ID and DELETED!=1)")
    private Double cgbhsje;

    @Formula("(select sum(t.JE) from T_BIZ_GLFY t where t.CGD_ID=ID and DELETED!=1)")
    private Double glfyje;

    @OneToMany(fetch = FetchType.LAZY, targetEntity = Kh.class)
    @Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
    @JoinColumn(name = "CGD_ID")
    @Where(clause = "deleted!='1'")
    private List<Kh> khList;

    /**
     * 关联ID
     */
    private Long glId;
    /**
     * 附件
     */
    @OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY, targetEntity = Fj.class)
    @JoinColumn(name = "CGD_ID")
    private List<Fj> fjList;

    public List<Fj> getFjList() {
        return fjList;
    }

    public void setFjList(List<Fj> fjList) {
        this.fjList = fjList;
    }

    private Date fksj;

    /**
     * 操作状态
     */
    @Transient
    private String czzt;

    /**
     * 会计年
     */
    @Column(name = "jiuqi_acctyear")
    private Integer acctyear;
    /**
     * 生成久其凭证时提供的ID
     */
    @Column(name = "jiuqi_uuid")
    private String uuid;
    /**
     * 久其返回的凭证ID
     */
    @Column(name = "jiuqi_voucher_id")
    private String voucherId;
    /**
     * 久其返回的凭证号
     */
    @Column(name = "jiuqi_voucher_num")
    private Integer voucherNum;
    /**
     * “久其插入标示”代码   1=未导入,2=导入开始,3=导入成功
     */
    @Column(name = "jiuqi_insert_flag")
    private Integer insertFlag = 1;
    /**
     * "久其删除标示”代码   1=未删除,2=删除开始,3=删除成功
     */
    @Column(name = "jiuqi_delete_flag")
    private Integer deleteFlag = 1;

    private Date drrq;

    private String serialNumber;


    /**
     * 是否过户
     */
    private Boolean sfgh = false;

    public String getSerialNumber() {
        return serialNumber;
    }

    public void setSerialNumber(String serialNumber) {
        this.serialNumber = serialNumber;
    }

    public Boolean getSfgh() {
        return sfgh;
    }

    public void setSfgh(Boolean sfgh) {
        this.sfgh = sfgh;
    }

    public Date getFksj() {
        return fksj;
    }

    public void setFksj(Date fksj) {
        this.fksj = fksj;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public List<Kh> getKhList() {
        return khList;
    }

    public void setKhList(List<Kh> khList) {
        this.khList = khList;
    }

    public String getCgdh() {
        return cgdh;
    }

    public void setCgdh(String cgdh) {
        this.cgdh = cgdh;
    }

    public String getCglx() {
        return cglx;
    }

    public void setCglx(String cglx) {
        this.cglx = cglx;
    }

    public Gsjg getGys() {
        return gys;
    }

    public void setGys(Gsjg gys) {
        this.gys = gys;
    }

    public Gsjg getFhgs() {
        return fhgs;
    }

    public void setFhgs(Gsjg fhgs) {
        this.fhgs = fhgs;
    }

    public Cght getCght() {
        return cght;
    }

    public void setCght(Cght cght) {
        this.cght = cght;
    }

    public String getCyh() {
        return cyh;
    }

    public void setCyh(String cyh) {
        this.cyh = cyh;
    }

    public Ck getDzck() {
        return dzck;
    }

    public void setDzck(Ck dzck) {
        this.dzck = dzck;
    }

    public Date getFhrq() {
        return fhrq;
    }

    public void setFhrq(Date fhrq) {
        this.fhrq = fhrq;
    }

    public Date getJhdhrq() {
        return jhdhrq;
    }

    public void setJhdhrq(Date jhdhrq) {
        this.jhdhrq = jhdhrq;
    }

    public Wls getYsdw() {
        return ysdw;
    }

    public void setYsdw(Wls ysdw) {
        this.ysdw = ysdw;
    }

    public List<Ysgj> getYsgjList() {
        return ysgjList;
    }

    public void setYsgjList(List<Ysgj> ysgjList) {
        this.ysgjList = ysgjList;
    }

    public String getLxrdh() {
        return lxrdh;
    }

    public void setLxrdh(String lxrdh) {
        this.lxrdh = lxrdh;
    }

    public Date getCgsj() {
        return cgsj;
    }

    public void setCgsj(Date cgsj) {
        this.cgsj = cgsj;
    }

    public String getSl() {
        return sl;
    }

    public void setSl(String sl) {
        this.sl = sl;
    }

    public String getBz() {
        return bz;
    }

    public void setBz(String bz) {
        this.bz = bz;
    }

    public Gsjg getSbgs() {
        return sbgs;
    }

    public void setSbgs(Gsjg sbgs) {
        this.sbgs = sbgs;
    }

    public Gsjg getSbbm() {
        return sbbm;
    }

    public void setSbbm(Gsjg sbbm) {
        this.sbbm = sbbm;
    }

    public Yg getSbr() {
        return sbr;
    }

    public void setSbr(Yg sbr) {
        this.sbr = sbr;
    }

    public Gsjg getCggs() {
        return cggs;
    }

    public void setCggs(Gsjg cggs) {
        this.cggs = cggs;
    }

    public Gsjg getCgbm() {
        return cgbm;
    }

    public void setCgbm(Gsjg cgbm) {
        this.cgbm = cgbm;
    }

    public Yg getCgr() {
        return cgr;
    }

    public void setCgr(Yg cgr) {
        this.cgr = cgr;
    }

    public List<Cgdmx> getCgdmxList() {
        return cgdmxList;
    }

    public void setCgdmxList(List<Cgdmx> cgdmxList) {
        this.cgdmxList = cgdmxList;
    }

    public List<Glfy> getCgfyList() {
        return cgfyList;
    }

    public void setCgfyList(List<Glfy> cgfyList) {
        this.cgfyList = cgfyList;
    }

    public boolean isSftzd() {
        return sftzd;
    }

    public void setSftzd(boolean sftzd) {
        this.sftzd = sftzd;
    }

    public Cgd getGltzd() {
        return gltzd;
    }

    public void setGltzd(Cgd gltzd) {
        this.gltzd = gltzd;
    }

    public Jsd getCgjsd() {
        return cgjsd;
    }

    public void setCgjsd(Jsd cgjsd) {
        this.cgjsd = cgjsd;
    }

    public Xsd getXsd() {
        return xsd;
    }

    public void setXsd(Xsd xsd) {
        this.xsd = xsd;
    }

    public String getZt() {
        return zt;
    }

    public void setZt(String zt) {
        this.zt = zt;
    }

    public String getTzsqzt() {
        return tzsqzt;
    }

    public void setTzsqzt(String tzsqzt) {
        this.tzsqzt = tzsqzt;
    }

    public Boolean getSfnb() {
        return sfnb;
    }

    public void setSfnb(Boolean sfnb) {
        this.sfnb = sfnb;
    }

    public Boolean getYsh() {
        return ysh;
    }

    public void setYsh(Boolean ysh) {
        this.ysh = ysh;
    }

    public Boolean getYrk() {
        return yrk;
    }

    public void setYrk(Boolean yrk) {
        this.yrk = yrk;
    }

    public Boolean getYjs() {
        return yjs;
    }

    public void setYjs(Boolean yjs) {
        this.yjs = yjs;
    }

    public Double getDsyfje() {
        return dsyfje;
    }

    public void setDsyfje(Double dsyfje) {
        this.dsyfje = dsyfje;
    }

    public Date getRksj() {
        return rksj;
    }

    public void setRksj(Date rksj) {
        this.rksj = rksj;
    }

    public Yg getRkr() {
        return rkr;
    }

    public void setRkr(Yg rkr) {
        this.rkr = rkr;
    }

    public Cgd getYcgd() {
        return ycgd;
    }

    public void setYcgd(Cgd ycgd) {
        this.ycgd = ycgd;
    }

    public Lj getLj() {
        return lj;
    }

    public void setLj(Lj lj) {
        this.lj = lj;
    }

    public Double getCgsl() {
        return cgsl;
    }

    public void setCgsl(Double cgsl) {
        this.cgsl = cgsl;
    }

    public Double getCgje() {
        return cgje;
    }

    public void setCgje(Double cgje) {
        this.cgje = cgje;
    }

    public Double getCgbhsje() {
        return cgbhsje;
    }

    public void setCgbhsje(Double cgbhsje) {
        this.cgbhsje = cgbhsje;
    }

    public Double getGlfyje() {
        return glfyje;
    }

    public void setGlfyje(Double glfyje) {
        this.glfyje = glfyje;
    }

    public Long getGlId() {
        return glId;
    }

    public void setGlId(Long glId) {
        this.glId = glId;
    }

    public Date getYsrq() {
        return ysrq;
    }

    public void setYsrq(Date ysrq) {
        this.ysrq = ysrq;
    }

    public Yg getYsr() {
        return ysr;
    }

    public void setYsr(Yg ysr) {
        this.ysr = ysr;
    }

    public Boolean getSfys() {
        return sfys;
    }

    public void setSfys(Boolean sfys) {
        this.sfys = sfys;
    }

    public Cgd getBccgd() {
        return bccgd;
    }

    public void setBccgd(Cgd bccgd) {
        this.bccgd = bccgd;
    }

    public Boolean getEndFlag() {
        return endFlag;
    }

    public void setEndFlag(Boolean endFlag) {
        this.endFlag = endFlag;
    }

    public String getCzzt() {
        return czzt;
    }

    public void setCzzt(String czzt) {
        this.czzt = czzt;
    }

    public Integer getAcctyear() {
        return acctyear;
    }

    public void setAcctyear(Integer acctyear) {
        this.acctyear = acctyear;
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getVoucherId() {
        return voucherId;
    }

    public void setVoucherId(String voucherId) {
        this.voucherId = voucherId;
    }

    public Integer getVoucherNum() {
        return voucherNum;
    }

    public void setVoucherNum(Integer voucherNum) {
        this.voucherNum = voucherNum;
    }

    public Integer getInsertFlag() {
        return insertFlag;
    }

    public void setInsertFlag(Integer insertFlag) {
        this.insertFlag = insertFlag;
    }

    public Integer getDeleteFlag() {
        return deleteFlag;
    }

    public void setDeleteFlag(Integer deleteFlag) {
        this.deleteFlag = deleteFlag;
    }

    public Date getDrrq() {
        return drrq;
    }

    public void setDrrq(Date drrq) {
        this.drrq = drrq;
    }
}
